package com.example.springcloudwinter.controller;

import com.example.springcloudwinter.dto.ResultEntity;
import com.example.springcloudwinter.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;


@RefreshScope
@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;
    
    @GetMapping("/listCart")
    public ResultEntity<?> listCart(@RequestParam("userId")String username, @RequestParam("businessId")int businessId){
        return cartService.listCart(username,businessId);
    }
    
    @PostMapping("/addCart")
    public ResultEntity<?> saveCart(@RequestParam("userId")String username, @RequestParam("businessId")int businessId,
                                    @RequestParam("foodId")int foodId){
        return cartService.saveCart(username,businessId,foodId);
    }
    
    @PostMapping("/subCart")
    public ResultEntity<?> removeCart(@RequestParam("userId")String username, @RequestParam("businessId")int businessId,
                                      @RequestParam("foodId")int foodId){
        return cartService.removeCart(username, businessId, foodId);
    }
}